<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 
        :nth-of-type(n)
        区分类型，不同类型的第n个子元素
         */
        .box :nth-of-type(2){
            background-color: red;
        }
        .box :nth-last-of-type(2){
            background-color: blue;
        }
        .box p:nth-last-of-type(1){
            background-color: green;
        }
    </style>
</head>

<body>
    <div class="box">
        <p>p1</p>
        <div>div1</div>
        
        <div>div2</div>
        <p>p2</p>
        <p>p3</p>
        <div>div3</div>
        <p>p4</p>
        <div>div4</div>
    </div>
</body>

</html>